package com.woniu.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.woniu.common.utils.PageData;
import com.woniu.common.utils.ResponseData;
import com.woniu.order.feign.ZfWorkFeign;
import com.woniu.order.pojo.ZfOrder;
import com.woniu.order.pojo.ZfTraderdetails;
import com.woniu.order.service.ZfTraderdetailsService;
import com.woniu.order.mapper.ZfTraderdetailsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author HP
 * @description 针对表【zf_traderdetails(分销商订单详情表)】的数据库操作Service实现
 * @createDate 2024-11-25 15:55:43
 */
@Service
public class ZfTraderdetailsServiceImpl extends ServiceImpl<ZfTraderdetailsMapper, ZfTraderdetails>
        implements ZfTraderdetailsService {
    @Autowired
    private ZfTraderdetailsMapper zfTraderdetailsMapper;
    @Autowired
    private ZfWorkFeign zfWorkFeign;


    /**
     * 审批通过订单，修改状态
     *
     * @return
     */
    @Override
    public ResponseData<?> addOrder(String code) {
        // 经理审批
        zfWorkFeign.approveTask("taskId", null);

        // 根据code(唯一约束)码修改数据库状态status
        UpdateWrapper<ZfTraderdetails> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("code", code).set("status", "-1");

        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> addOrder2(String code) {
        // 总监审批

        // success修改数据库状态
        UpdateWrapper<ZfTraderdetails> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("code", code).set("status", "-2");

        // fail修改数据库状态
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> batchDelete(List<String> ids) {
        zfTraderdetailsMapper.batchDelete(ids);
        return new ResponseData<>().ok();
    }
}